gusucode.com > 支持向量机工具箱 - LIBSVM OSU_SVM LS_SVM源码程序 > 支持向量机工具箱 - LIBSVM OSU_SVM LS_SVM\stprtool\datasets\pgm2xi.m

    function [X,I,K,width,height]=pgm2xi(root,from,to)
% [X,I,K,width,height]=pgm2xi(root,from,to)
%
% PGM2XI reads PGM.* images from directories numbered by 
%   numbers from - to. These directories are in the root 
%   directory. Loaded images are reshaped to the vector.
%
% Input:
%  root [string] name of the direcory where the numbered
%          direecories are placed.
%  from [1x1] number coresponding to the first class - name
%          of directory.
%  to [1x1] number coresponding to the last class - name
%          of directory.
%
% Output:
%  X [DxN] loaded images stored as N vectors of dimension D.
%  I [1xN] class labels of the vectors X which correspond to
%          the direcotry names (numbers).
%  K [1xC] contains numbers of vectors in each class. The C is 
%          number of classes.
%  width [1x1] image width.
%  height [1x1] image height.
%
% See also X2PGM, PGM2X
%

% Statistical Pattern Recognition Toolbox, Vojtech Franc, Vaclav Hlavac
% (c) Czech Technical University Prague, http://cmp.felk.cvut.cz
% Written Vojtech Franc (diploma thesis)
% Modifications
% 27-feb-2001 V.Franc

K=zeros(1,to-from+1);
X=[];
I=[];

for class=from:to,
  
  cdir=dir([root '/' num2str(class)]);
  
  for i=1:size(cdir,1),
    
    if cdir(i).isdir == 0,
      
      [x,width,height]=pgm2x([root '/' num2str(class) '/' cdir(i).name]);

      K(class-from+1)=K(class-from+1)+1;
      X=[X,x];
      I=[I class];
      
    end
  end
  
end

return;